Add support for perceptual image encoding#3113
Draft
BezBIS wants to merge 1 commit intogetzola:nextfrom
Draft
Conversation
0ee0220 to
8b4f718
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
IMPORTANT: Please do not create a Pull Request adding a new feature without discussing it first.
The place to discuss new features is the forum: https://zola.discourse.group/
If you want to add a new feature, please open a thread there first in the feature requests section.
Sanity check:
Code changes
(Delete or ignore this section for documentation changes)
nextbranch?If the change is a new feature or adding to/changing an existing one:
This draft pr adds support for perceptual image compression as a post-processing step as discussed in #1429. To enable this feature, users would add a new section to the
config.tomldefining glob patterns and compression options:How it works?
As the last stage of
zola buildbefore copyingstaticto the output folder, thestaticdirectory is searched for files matching each glob pattern, and perceptual image compression is run on them according to the configured options. Compressed files are then output to the newcompressed_filesdirectory, and any older compressed images not found in the build are cleaned out. Finally, allhtmlfiles in thepublicdirectory are scanned for links to raw images, and updated to instead link to the compressed version.Pros of this approach
build,serveshould remain quick.staticmatching defined globs can be compressed, not just those processed in-template withprocess_image.Cons of this approach
process_imageto output lossless or high quality level images: perceptual compression needs high quality source images, or perceived quality may actually decrease. This could cause issues when combined with the above (if all images are output as png to preserve maximum quality, there is no way of knowing which are intend to remain as png, or which to be converted to jpeg etc).publicfolder. E.g. one copy inprocessed_imagesand another incompressed_images. This may not be a problem for many users, but could cause issues with larger sites on small hosting plans, or those who upload files via ftp / scp etc.My thoughts
In my opinion, I think the cons of this approach may outweigh the pros vs adding support for perceptual encoding directly to
process_image. Serve will be much faster this way, but the cost is substantial loss of flexibility when it comes to deciding output format on an image by image basis, and large amounts of duplication in the final public folder.However, I would welcome any discussion and am happy to proceed with this approach if the consensus is it is the better option for users. My current approach is very naive, and there may be a better way of adding this as a post-processing step that fits better with the existing processes etc.